package de.homer.persistence.adapter;

import java.util.Collection;

import org.springframework.stereotype.Repository;

import de.homer.adapter.domain.PluginMetaInformation;
import de.homer.persistence.AbstractRepositoryJPA;

/**
 * JPA implementation of {@link PluginRepository}.
 * 
 * @author André Stannek
 * @see PluginRepository
 * 
 */
@Repository
public class PluginRepositoryJPA extends
		AbstractRepositoryJPA<PluginMetaInformation> implements
		PluginRepository {

	/**
	 * 
	 */
	private static final long serialVersionUID = 5757420860344386020L;

	/*
	 * (non-Javadoc)
	 * 
	 * @see de.homer.core.repository.Repository#getAll()
	 */
	@Override
	public final Collection<PluginMetaInformation> getAll() {
		return getAll(PluginMetaInformation.class);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see de.homer.adapter.repository.AdapterRepository#find(java.lang.String)
	 */
	@Override
	public final PluginMetaInformation find(final String className) {
		Collection<PluginMetaInformation> adapters = getAll();
		for (PluginMetaInformation adapterDescriptor : adapters) {
			if (adapterDescriptor.getPluginClassName().equals(className)) {
				return adapterDescriptor;
			}
		}
		return null;
	}
}
